﻿// *----------------------------------------------------------------
// Copyright (C) 2017 通通优品
// 版权所有。
// 
// 类名：IRepositoryOfTEntityAndTPrimaryKey.cs
// 功能描述：TongTongMall
// 
// Create User：jym 2017/02/09
// 
// Edit User：UserName,EditTime
// Describe：Describe
// ----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using TongTongMall.Domain.PredicateForDapper;
using TongTongMall.Domain.Repositories.Entities;

namespace TongTongMall.Domain.Repositories.Repositories
{
    /// <summary>
    /// This interface is implemented by all repositories to ensure implementation of fixed methods.
    /// </summary>
    /// <typeparam name="TEntity">Main Entity type this repository works on</typeparam>
    /// <typeparam name="TPrimaryKey">Primary key type of the entity</typeparam>
    public interface IRepository<TEntity, TPrimaryKey> : IRepository where TEntity : class, IEntity<TPrimaryKey>
    {
        #region Select/Get/Query


        List<TEntity> GetAllList(object whereClip = null, IList<ISort> orderClip = null, Expression<Func<TEntity, object>> selector = null);

        Task<List<TEntity>> GetAllListAsync(object whereClip = null, IList<ISort> orderClip = null, Expression<Func<TEntity, object>> selector = null);
        
        TEntity FirstOrDefault(object whereClip = null, IList<ISort> orderClip = null, Expression<Func<TEntity, object>> selector = null);

        Task<TEntity> FirstOrDefaultAsync(object whereClip = null, IList<ISort> orderClip = null, Expression<Func<TEntity, object>> selector = null);

        #endregion

        #region Insert

        TPrimaryKey Insert(TEntity entity);

        Task<TPrimaryKey> InsertAsync(TEntity entity);


        #endregion

        #region Update
        bool Update(TEntity entity);

        Task<bool> UpdateAsync(TEntity entity);

        bool Update(object entity, object whereClip);

        Task<bool> UpdateAsync(object entity, object whereClip);
        #endregion

        #region Delete


        bool Delete(object whereClip);

        Task<bool> DeleteAsync(object whereClip);
        
        #endregion

        #region Aggregates

        int Count(object whereClip = null);

        Task<int> CountAsync(object whereClip = null);

        #endregion

        #region PageBy

        IEnumerable<TEntity> QueryPaged(int pageIndex, int pageSize, object whereClip = null, IList<ISort> orderClip = null, Expression<Func<TEntity, object>> selector = null);

        Task<IEnumerable<TEntity>> QueryPagedAsync(int pageIndex, int pageSize, object whereClip = null, IList<ISort> orderClip = null, Expression<Func<TEntity, object>> selector = null);

        #endregion
    }
}
